Ext.define('AmpleHarvest.objects.files.cContextMenu',
{
	extend				: 'Ext.menu.Menu',
	alias				: 'widget.ampleharvest-objects-files-ccontextmenu',
	plain				: true,
	floating			: true,
	renderTo			: Ext.getBody(),
	requires			:
	[
		'Ext.menu.Item'
	],
	m_obj_Window		: null,

	initComponent		: function()
	{
		this.m_obj_Download = Ext.create('Ext.menu.Item',
		{
			iconCls	: "toolbar-article-navigation-files-download",
			text	: 'Download',
			handler	: function(rowIndex)
			{
				var arr_Recs = this.m_obj_Window.up('ampleharvest-objects-files-cfiles')
						.getSelectionModel().getSelection();
				Ext.Array.each(arr_Recs, function(obj, index, arr_all)
				{
					var obj_Dowload = obj.get('download');
					if (!obj_Dowload)
					{
						alert("No Download");
					}
					m_obj_AmpleHarvest_ViewPort
							.fireEvent(
									AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_REDIRECT,
									obj_Dowload.serverId, obj_Dowload.id
							);
				}
				);
			},
			scope	: this
		}
		);
		this.m_obj_Open = Ext.create('Ext.menu.Item',
		{
			text	: 'View',
			iconCls	: 'toolbar-article-navigation-files-view',
			handler	: function(rowIndex)
			{
				var arr_Recs = this.m_obj_Window.up('fileWindow')
						.getSelectionModel().getSelection();
				Ext.Array.each(arr_Recs, function(obj, index, arr_all)
				{
					var obj_Dowload = obj.get('htmlDisplay');
					if (!obj_Dowload)
					{
						alert("No Download");
					}
					m_obj_AmpleHarvest_ViewPort
							.fireEvent(
									AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_REDIRECT,
									obj_Dowload.serverId, obj_Dowload.id
							);
				}
				);
			},
			scope	: this
		}
		);
		this.m_obj_Info = Ext.create('Ext.menu.Item',
		{
			text	: 'Info',
			iconCls	: 'toolbar-article-navigation-files-info',
			handler	: function(rowIndex)
			{
				var arr_Recs = this.m_obj_Window.up('ampleharvest-objects-files-cfiles')
						.getSelectionModel().getSelection();
				Ext.Array.each(arr_Recs, function(obj, index, arr_all)
				{
					var obj_Info = obj.get('metadata');
					var obj_Text = obj.get('text');
					if (!obj_Info)
					{
						alert("No Additonal Infomration");
					}
					if (!obj_Text)
					{
						alert("No File Title");
					}
					m_obj_AmpleHarvest_ViewPort
							.fireEvent(
									AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_OPEN_FILE_INFO,
									obj_Text,obj_Info 
							);
				}
				);
			},
			scope	: this
		}
		);
		this.items =
		[
				this.m_obj_Download, this.m_obj_Open, this.m_obj_Info
		];

		this.callParent();
	},
	set_ButtonStatus	: function(obj_Button, bool_Status)
	{
		if (bool_Status)
		{
			obj_Button.enable();
		}
		else
		{
			obj_Button.disable();
		}
	},

	set_Download		: function(bool_Status)
	{
		this.set_ButtonStatus(this.m_obj_Download, bool_Status);
	},
	set_Open			: function(bool_Status)
	{
		this.set_ButtonStatus(this.m_obj_Open, bool_Status);
	},
	set_Info			: function(bool_Status)
	{
		this.set_ButtonStatus(this.m_obj_Info, bool_Status);
	}
}
);